import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { FetchService } from '../../../core/net/fetch.service';

@Component({
  selector: 'app-abnormal-records',
  templateUrl: './abnormal-records.component.html',
  styleUrls: ['./abnormal-records.component.scss']
})
export class AbnormalRecordsComponent implements OnInit {
    searchForm: FormGroup;
    tableData = [];
    tableWidthConfig = ['75px', '220px', '150px', '150px', '250px', '150px', '150px'];
    pageNum = 1;
    pageSize = 10;
    total: number;
    loading = false;

    constructor(private fb: FormBuilder,
                private fetchService: FetchService) {
        this.searchForm = this.fb.group({
            watergateCode: [null]
        });
    }

    ngOnInit(): void {
        this.queryInfo();
    }

    queryInfo(reset: boolean = false): void {
        if (reset) {
            this.pageNum = 1;
        }
        this.loading = true;
        const params = {
            ...this.searchForm.value,
            pageNum: this.pageNum,
            pageSize: this.pageSize
        };
        this.fetchService.post('base/wrsBrwaterDam/queryErrorList', params).subscribe(res => {
            this.tableData = res['list'];
            this.total = res['total'];
            this.loading = false;
        });
    }
}
